package com.aaa.stock.service.impl;


import com.aaa.entity.Role;
import com.aaa.entity.StockMedicines;
import com.aaa.entity.StockProducer;

import com.aaa.stock.dao.CheckItemDao;
import com.aaa.stock.dao.MedicinesDao;
import com.aaa.stock.dao.ProducerDao;
import com.aaa.stock.service.MedicinesService;
import com.aaa.stock.vo.MedicinesVo;
import com.aaa.stock.vo.MedicinesrVo;
import com.aaa.util.JwtUtil;
import com.aaa.util.WebUtil;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class MedicinesServiceImpl extends ServiceImpl<MedicinesDao,StockMedicines> implements MedicinesService {

    @Autowired
    private MedicinesDao medicinesDao;
    @Autowired
    private ProducerDao producerDao;

    //查询全部
    @Override
    public Result<List<StockProducer>> getAll() {
        QueryWrapper<StockProducer> wrapper = new QueryWrapper<>();
        wrapper.eq("status","0");
        List<StockProducer> stockProducers = producerDao.selectList(wrapper);
        return new Result(2000,"查询成功",stockProducers);
    }
    //查询分页
    @Override
    public Result<IPage<StockMedicines>> getByPage(Integer currentPage, Integer pageSize, MedicinesrVo medicinesrVo) {
        IPage<StockMedicines> page=new Page<>(currentPage,pageSize);
        QueryWrapper<StockMedicines> wrapper=new QueryWrapper<>();
        if (StringUtils.hasText(medicinesrVo.getMedicinesName())){
            wrapper.like("medicines_name",medicinesrVo.getMedicinesName());
        }
        if (StringUtils.hasText(medicinesrVo.getKeywords())){
            wrapper.like("keywords",medicinesrVo.getKeywords());
        }
        if (Objects.nonNull(medicinesrVo.getMedicinesType())){
            wrapper.eq("medicines_type",medicinesrVo.getMedicinesType());
        }
        if (Objects.nonNull(medicinesrVo.getProducterId())){
            wrapper.eq("producter_id",medicinesrVo.getProducterId());
        }
        if (Objects.nonNull(medicinesrVo.getPrescriptionType())){
            wrapper.eq("prescription_type",medicinesrVo.getPrescriptionType());
        }
        if(Objects.nonNull(medicinesrVo.getStatus())){
            wrapper.eq("status",medicinesrVo.getStatus());
        }
        if(Objects.nonNull(medicinesrVo.getDateRange())&&medicinesrVo.getDateRange().length==2){
            wrapper.between("create_time",medicinesrVo.getDateRange()[0],medicinesrVo.getDateRange()[1]);
        }
        IPage<StockMedicines>page1=medicinesDao.selectPage(page,wrapper);
        return new Result<>(2000,"查询=========成功",page1);
    }






    //     对外提供接口
    @Autowired
    private CheckItemDao checkItemDao;

    @Override
    public Result<IPage<StockMedicines>> findByConditio(Integer currentPage, Integer pageSize, MedicinesVo medicinesVo) {
        IPage<StockMedicines> page = new Page<>(currentPage, pageSize);
        QueryWrapper<StockMedicines> wrapper = new QueryWrapper<>();

        //关键字
        if (StringUtils.hasText(medicinesVo.getKeywords())) {
            wrapper.like("keywords", medicinesVo.getKeywords());
        }

        IPage<StockMedicines> page1 = checkItemDao.selectPage(page, wrapper);
        return new Result<IPage<StockMedicines>>(2000, "查询用户成功", page1);
    }





}




